package com.ag.zrt.action;

import javax.annotation.Resource;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbType;
import com.ag.common.BaseAction;
import com.ag.zrt.service.TypeService;
@Controller("addTypeAction")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AddTypeAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1165471530382200778L;
	@Resource(name="TypeService")
	private TypeService typeService;
	private TbType type = new TbType();
	private String typeName;
	private String typeDetail;
	private String msg;
	private String errorDetail;

	public String getMsg() {
		return msg;
	}

	public String getErrorDetail() {
		return errorDetail;
	}

	public void setTypeService(TypeService typeService) {
		this.typeService = typeService;
	}

	public void setTypeName(String typeName) {
		this.typeName = typeName;
	}

	public void setTypeDetail(String typeDetail) {
		this.typeDetail = typeDetail;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		try {
			type.setTpyeDetail(typeDetail);
			type.setTpyeName(typeName);
			msg = "添加成功";
			errorDetail= "";
			typeService.save(type);
			return "add_type_succ";
		} catch (Exception e) {
			msg = "添加失败";
			errorDetail = e.toString();
			return "add_type_failed";
		}
	}

}
